package com.bw.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.bw.service.OrderInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @author 31629
 * @date 2025年08月29日 10:50
 */
@RestController
public class OrderInfoController {

  @Autowired
    private OrderInfoService orderInfoService;
  @RequestMapping("/s1")
   public JSONObject select1(){
      //声明返回值
      JSONObject result = new JSONObject();
      //存入需要返回的数据
      result.put("status",0);
      result.put("msg",0);
      //data数据
      JSONObject data = new JSONObject();
      result.put("data",data);
      //data 中数据存入
      JSONArray columns = new JSONArray();
      JSONArray rows = new JSONArray();

      //存入data中
      data.put("columns",columns);
      data.put("rows",rows);
      //列数据  列的标题
      JSONObject c1 = new JSONObject();
      c1.put("id","cta");
      c1.put("name","下单金额");

      JSONObject c2= new JSONObject();
      c2.put("id","ctb");
      c2.put("name","下单次数");

      JSONObject c3 = new JSONObject();
      c3.put("id","ctc");
      c3.put("name","下单人数");

      JSONObject c4= new JSONObject();
      c4.put("id","ctd");
      c4.put("name","实收金额");

      JSONObject c5= new JSONObject();
      c5.put("id","cte");
      c5.put("name","退款成功金额");

      //存入到列中
      columns.add(c1);
      columns.add(c2);
      columns.add(c3);
      columns.add(c4);
      columns.add(c5);

      List<Map<String, Object>> maps = orderInfoService.select1();
      for (Map<String, Object> map : maps) {
          JSONObject row = new JSONObject();
          row.put("cta",map.get("cta"));
          row.put("ctb",map.get("ctb"));
          row.put("ctc",map.get("ctc"));
          row.put("ctd",map.get("ctd"));
          row.put("cte",map.get("cte"));
          rows.add(row);
      }


      return result;
  }

  @RequestMapping("/s2")
  public JSONObject select2(){
      //定义返回结果
      JSONObject result= new JSONObject();
      result.put("status",0);
      result.put("msg","");
      JSONObject data= new JSONObject();
      result.put("data",data);
      JSONArray columns = new JSONArray();
      JSONArray rows = new JSONArray();

      data.put("columns",columns);
      data.put("rows",rows);

      JSONObject col1 = new JSONObject();
      col1.put("id","dt");
      col1.put("name","日期");

      JSONObject col2 = new JSONObject();
      col2.put("id","day");
      col2.put("name","天数");

      JSONObject col3 = new JSONObject();
      col3.put("id","cta");
      col3.put("name","直营店优惠分摊支出金额");

      JSONObject col4 = new JSONObject();
      col4.put("id","ctb");
      col4.put("name","加盟店优惠分摊支出金额");

      columns.add(col1);
      columns.add(col2);
      columns.add(col3);
      columns.add(col4);

      List<Map<String, Object>> maps = orderInfoService.select2();
      for (Map<String, Object> map : maps) {
          JSONObject row = new JSONObject();
          row.put("dt",map.get("dt"));
          row.put("day",map.get("day"));
          row.put("cta",map.get("cta"));
          row.put("ctb",map.get("ctb"));
          rows.add(row);
      }
      return result;
  }
}
